<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>易购 我的购物车</title>
    <link rel="icon" href="/img/favicon.ico">

    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" type="text/css" href="/css/all.css" />
    <link rel="stylesheet" type="text/css" href="/css/pages-cart.css" />

    <div th:include="common/head :: head"></div>
</head>

<body onunload="javascript:hm.postData();">
<!--head-->
<!-- 头部栏位 -->
<!--页面顶部-->
<div th:include="common/header :: header"></div>


<div class="cart py-container">
    <!--All goods-->
    <div class="allgoods" id="itemArray">
        <h4>全部商品<span></span></h4>
        <div class="cart-main">
            <div class="yui3-g cart-th">
                <div class="yui3-u-1-4"><input class="chooseAll" type="checkbox" name="" id="" value="" /> 全部</div>
                <div class="yui3-u-1-4">商品</div>
                <div class="yui3-u-1-8">单价（元）</div>
                <div class="yui3-u-1-8">数量</div>
                <div class="yui3-u-1-8">小计（元）</div>
                <div class="yui3-u-1-8">操作</div>
            </div>
            <div class="cart-item-list" v-for="carInfoVo in data" :key="carInfoVo.id">
                <div style="padding: 2px; margin-bottom: -10px;color: red;margin-top: 10px;">{{carInfoVo.activityContent}}</div>
                <div class="cart-body">
                    <div class="cart-list hm-display-statistics" v-for="(item,index) in carInfoVo.cartInfoList" :key="item.id" :hm-display="'{\'displayType\':\'query\', \'item_type\': \'skuId\', \'item\': '+item.skuId+', \'order\': '+index+'}'">
                        <ul class="goods-list yui3-g">
                            <li class="yui3-u-1-24">
                                <input type="checkbox" v-model="item.isChecked" @click="checkCart(item)" name="chk_list"/>
                            </li>
                            <li class="yui3-u-6-24">
                                <div class="good-item">
                                    <div class="item-img"><a :href="'http://item.gmall.com/'+item.skuId+'.html'"><img :src="item.imgUrl"/></a></div>
                                    <div class="item-msg"><a :href="'http://item.gmall.com/'+item.skuId+'.html'">{{ item.skuName }}</a></div>
                                </div>
                            </li>
                            <li class="yui3-u-5-24">
                                <div class="item-txt"></div>
                            </li>
                            <li class="yui3-u-1-8">
                                <span class="price">￥{{ item.skuPrice }}</span>

                                <div v-if="carInfoVo.activityRuleList !== null  && carInfoVo.activityRuleList.length > 0">
                                    <a class="sales-promotion" :id="'activity_a_'+item.skuId" href="#none" @click="activityShow(item.skuId)" style="color: #E2231A;">促销<b></b></a>
                                    <div class="promotion-tips" :id="'activity_'+item.skuId" style="left: 675px; top:100px; display: none;">
                                        <div class="promotion-tit" style="width: 43px;">促销<b></b></div>
                                        <div class="promotion-cont">
                                            <ul>
                                                <!-- 满减 -->
                                                <li v-for="(activityRule, indexj) in carInfoVo.activityRuleList" :key="activityRule.id" v-if="activityRule.activityType == 'FULL_REDUCTION'"><input type="radio" :name="item.skuId" :value="indexj" v-model="activityRule.checked">满{{ activityRule.conditionAmount }}减{{ activityRule.benefitAmount }}元</li>
                                                <!-- 满减 -->
                                                <li v-for="(activityRule, indexj) in carInfoVo.activityRuleList" :key="activityRule.id" v-if="activityRule.activityType == 'FULL_DISCOUNT'"><input type="radio" :name="item.skuId" :value="indexj" v-model="activityRule.checked">满{{ activityRule.conditionNum}}件打{{ activityRule.benefitDiscount }}折</li>
                                            </ul>
                                            <div class="op-btns ac mt20">
<!--                                                <a href="#none" class="btn-1 select-promotion" @click="activitySure()">确定</a>-->
                                                <a href="#none" class="btn-9 ml10 del cancel-promotion" @click="close()">取消</a>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clr"></div>
                                </div>
<!--                                <p class="mt5" style="border: 1px solid #f9d2d3;color: #E2231A;margin-top: 0px; margin-bottom: 3px;width: 110px;" v-if="item.skuActivityReduceAmount != null">-->
<!--                                    <span class="pro-tiny-tip">促销优惠：¥{{ item.skuActivityReduceAmount }}</span>-->
<!--                                </p>-->

                                <div v-if="item.couponInfoList !== null && item.couponInfoList.length > 0">
                                    <a class="sales-promotion" :id="'couponInfo_a_'+item.skuId" href="#none" @click="couponInfoShow(item.skuId)" style="color: #E2231A;">优惠券<b></b></a>
                                    <div class="promotion-tips" :id="'couponInfo_'+item.skuId" style="left: 675px; top:100px; display: none;width:315px;'">
                                        <div class="promotion-tit" style="width: 43px;">优惠券<b></b></div>
                                        <div class="promotion-cont" style="width: auto;">

                                            <div class="p-coupon-item p-coupon-item-gray" v-for="couponInfo in item.couponInfoList" :key="couponInfo.id">
                                                <div class="coupon-price" style="border-color:#e74649;">
                                                    <span class="txt" v-if="couponInfo.couponType == 'CASH'" style="color: #e74649;">{{ couponInfo.benefitAmount }}元</span>
                                                    <span class="txt" v-if="couponInfo.couponType == 'DISCOUNT'" style="color: #e74649;">{{ couponInfo.benefitDiscount }}折</span>
                                                    <span class="txt" v-if="couponInfo.couponType == 'FULL_REDUCTION'" style="color: #e74649;">{{ couponInfo.benefitAmount }}元</span>
                                                    <span class="txt" v-if="couponInfo.couponType == 'FULL_DISCOUNT'" style="color: #e74649;">{{ couponInfo.benefitDiscount }}折</span>
                                                </div>
                                                <div class="coupon-msg">
                                                    <div>
                                                        <span class="ctype" v-if="couponInfo.couponType == 'CASH'">现金券</span>
                                                        <span class="ctype" v-if="couponInfo.couponType == 'DISCOUNT'">折扣券</span>
                                                        <span class="ctype" v-if="couponInfo.couponType == 'FULL_REDUCTION'">满减卷</span>
                                                        <span class="ctype" v-if="couponInfo.couponType == 'FULL_DISCOUNT'">满件打折卷</span>

                                                        <span class="cinfo" v-if="couponInfo.couponType == 'CASH'">现金券{{ couponInfo.benefitAmount }}元</span>
                                                        <span class="cinfo" v-if="couponInfo.couponType == 'DISCOUNT'">折扣券{{ couponInfo.benefitDiscount }}折</span>
                                                        <span class="cinfo" v-if="couponInfo.couponType == 'FULL_REDUCTION'">满{{ couponInfo.conditionAmount }}减{{ couponInfo.benefitAmount }}元</span>
                                                        <span class="cinfo" v-if="couponInfo.couponType == 'FULL_DISCOUNT'">满{{ couponInfo.conditionNum }}件打{{ couponInfo.benefitDiscount }}折</span>

                                                    </div>
                                                    <div class="clearfix">
                                                        <div class="ftx-03 J_cpitems">{{ couponInfo.rangeDesc }}</div>
                                                        <i class="zyc-ico"></i>
                                                    </div>
                                                </div>
                                                <div class="coupon-opbtns">
                                                    <span class="ftx-03" v-if="couponInfo.isGet > 0 && couponInfo.couponStatus == 'NOT_USED'">已领取</span>
                                                    <span class="ftx-03" v-if="couponInfo.isGet > 0 && couponInfo.couponStatus == 'USED'">已使用</span>
                                                    <span class="btn-1 coupon-btn hm-action-statistics" v-if="couponInfo.isGet == 0" @click="getCouponInfo(couponInfo.id)" :hm-action = "'{\'action_id\':\'get_coupon\', \'item_type\': \'couponId\', \'item\': '+couponInfo.id+'}'">领取</span>
                                                </div>
                                            </div>

                                            <div class="op-btns ac mt20">
                                                <a href="#none" class="btn-9 ml10 del cancel-promotion" @click="close()">取消</a>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clr"></div>
                                </div>

                            </li>
                            <li class="yui3-u-1-8">
                                <a href="javascript:void(0)" class="increment mins hm-action-statistics" @click="down(item)" :hm-action = "'{\'action_id\':\'cart_down\', \'item_type\': \'skuId\', \'item\': '+item.skuId+'}'">-</a>
                                <input :value="item.skuNum"  minnum="1" class="itxt" />
                                <a href="javascript:void(0)" class="increment plus hm-action-statistics" @click="add(item)" :hm-action = "'{\'action_id\':\'cart_add\', \'item_type\': \'skuId\', \'item\': '+item.skuId+'}'">+</a>
                            </li>
                            <li class="yui3-u-1-8"><span class="sum" >￥{{ item.skuPrice * item.skuNum }}</span></li>
                            <li class="yui3-u-1-8">
                                <a class="hm-action-statistics" href="javascript:void(0)" @click="deleteCart(item.skuId)" :hm-action = "'{\'action_id\':\'cart_remove\', \'item_type\': \'skuId\', \'item\': '+item.skuId+'}'">删除</a><br />
                                <a href="#none">移到收藏</a>
                            </li>
                        </ul>
                    </div>

                </div>
            </div>
        </div>
        <div class="cart-tool">
            <div class="select-all">
                <input class="chooseAll" type="checkbox"  name=""  value="" />
                <span>全选</span>
            </div>
            <div class="option">
                <a href="/cart/deleteChecked">删除选中的商品</a>
                <a href="/cart/collectChecked">移到我的收藏</a>
                <a href="#none">清除下柜商品</a>
            </div>
            <div class="money-box">
                <div class="chosed">已选择<span >{{count}}</span>件商品</div>
                <div class="sumprice">
                    <span><em>总价：</em><i class="summoney">￥{{total - activityReduceAmount}}</i></span><br/>
                    <span><em>促销：￥{{activityReduceAmount}}</em><i></i></span>
                </div>
                <div class="sumbtn">
                    <a class="sum-btn" href="javascript:" @click="trade()" style="color: #fff;">结算</a>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="liked">
            <ul class="sui-nav nav-tabs">
                <li class="active">
                    <a href="#index" data-toggle="tab">猜你喜欢</a>
                </li>
                <li>
                    <a href="#profile" data-toggle="tab">特惠换购</a>
                </li>
            </ul>
            <div class="clearfix"></div>
            <div class="tab-content">
                <div id="index" class="tab-pane active">
                    <div id="myCarousel" data-ride="carousel" data-interval="4000" class="sui-carousel slide">
                        <div class="carousel-inner">
                            <div class="active item">
                                <ul>
                                    <li>
                                        <img src="/img/like1.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                    <li>
                                        <img src="/img/like2.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                    <li>
                                        <img src="/img/like3.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                    <li>
                                        <img src="/img/like4.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            <div class="item">
                                <ul>
                                    <li>
                                        <img src="/img/like1.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                    <li>
                                        <img src="/img/like2.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                    <li>
                                        <img src="/img/like3.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                    <li>
                                        <img src="/img/like4.png" />
                                        <div class="intro">
                                            <i>Apple苹果iPhone 6s (A1699)</i>
                                        </div>
                                        <div class="money">
                                            <span>$29.00</span>
                                        </div>
                                        <div class="incar">
                                            <a href="#" class="sui-btn btn-bordered btn-xlarge btn-default"><i class="car"></i><span class="cartxt">加入购物车</span></a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <a href="#myCarousel" data-slide="prev" class="carousel-control left">‹</a>
                        <a href="#myCarousel" data-slide="next" class="carousel-control right">›</a>
                    </div>
                </div>
                <div id="profile" class="tab-pane">
                    <p>特惠选购</p>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 底部栏位 -->
<!--页面底部-->
<div class="clearfix footer">
    <div class="py-container">
        <div class="footlink">
            <div class="clearfix Mod-list">
                <div class="yui3-g">
                    <div class="yui3-u-1-6">
                        <h4>购物指南</h4>
                        <ul class="unstyled">
                            <li>购物流程</li>
                            <li>会员介绍</li>
                            <li>生活旅行/团购</li>
                            <li>常见问题</li>
                            <li>购物指南</li>
                        </ul>

                    </div>
                    <div class="yui3-u-1-6">
                        <h4>配送方式</h4>
                        <ul class="unstyled">
                            <li>上门自提</li>
                            <li>211限时达</li>
                            <li>配送服务查询</li>
                            <li>配送费收取标准</li>
                            <li>海外配送</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>支付方式</h4>
                        <ul class="unstyled">
                            <li>货到付款</li>
                            <li>在线支付</li>
                            <li>分期付款</li>
                            <li>邮局汇款</li>
                            <li>公司转账</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>售后服务</h4>
                        <ul class="unstyled">
                            <li>售后政策</li>
                            <li>价格保护</li>
                            <li>退款说明</li>
                            <li>返修/退换货</li>
                            <li>取消订单</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>特色服务</h4>
                        <ul class="unstyled">
                            <li>夺宝岛</li>
                            <li>DIY装机</li>
                            <li>延保服务</li>
                            <li>易购E卡</li>
                            <li>易购通信</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>帮助中心</h4>
                        <img src="./img/wx_cz.jpg">
                    </div>
                </div>
            </div>
            <div class="Mod-copyright">
                <ul class="helpLink">
                    <li>关于我们<span class="space"></span></li>
                    <li>联系我们<span class="space"></span></li>
                    <li>关于我们<span class="space"></span></li>
                    <li>商家入驻<span class="space"></span></li>
                    <li>营销中心<span class="space"></span></li>
                    <li>友情链接<span class="space"></span></li>
                    <li>关于我们<span class="space"></span></li>
                    <li>营销中心<span class="space"></span></li>
                    <li>友情链接<span class="space"></span></li>
                    <li>关于我们</li>
                </ul>
                <p>地址：北京市昌平区</p>
                <p>京ICP备19006430号</p>
            </div>
        </div>
    </div>
</div>
<!--页面底部END-->
<script src="/js/api/cart.js"></script>
<script src="/js/api/activity.js"></script>
<script th:inline="javascript">
    var items = new Vue({
        el: '#itemArray',

        data: {
            data: {},
            count: 0,
            total: 0,
            activityReduceAmount: 0 // 促销金额
        },

        created() {
            this.init()
        },

        methods: {
            init() {
                cart.cartList().then(response => {
                    this.data = response.data.data

                    for(var i=0; i<this.data.length; i++) {
                        this.data[i].id = i;
                    }
                    this.compute()
                })
            },

            // 计算
            // compute() {
            //     if(this.data == null) return
            //     this.count = 0
            //     this.total = 0
            //     this.activityReduceAmount = 0
            //
            //     for(var i=0; i<this.data.length; i++) {
            //         if(this.data[i].activityRuleList != null && this.data[i].activityRuleList.length > 0) {
            //             var activityTotalAmount = 0;
            //             var activityTotalNum = 0;
            //             for(j=0; j<this.data[i].cartInfoList.length; j++) {
            //                 if (this.data[i].cartInfoList[j].isChecked == 1) {
            //                     // 计算促销金额
            //                     activityTotalAmount += this.data[i].cartInfoList[j].skuPrice * this.data[i].cartInfoList[j].skuNum;
            //                     activityTotalNum += this.data[i].cartInfoList[j].skuNum
            //                 }
            //             }
            //             this.total += activityTotalAmount
            //             this.count += this.data[i].cartInfoList.length
            //
            //             this.data[i].activityContent = ''
            //             for(j=0; j<this.data[i].activityRuleList.length; j++) {
            //                 //默认不选择
            //                 this.data[i].activityRuleList[j].checked = -1
            //             }
            //             for(j=0; j<this.data[i].activityRuleList.length; j++) {
            //                 if(this.data[i].activityRuleList[j].activityType == 'FULL_REDUCTION') {
            //                     // 促销金额必须满足
            //                     if(activityTotalAmount >= this.data[i].activityRuleList[j].conditionAmount) {
            //                         // 选中了促销单选按钮
            //                         var index = j;
            //                         if(this.data[i].activityRuleList[j].checked > -1) {
            //                             index = this.data[i].activityRuleList[j].checked;
            //                         }
            //                         var currentActivityReduceAmount = this.data[i].activityRuleList[index].benefitAmount
            //                         this.data[i].activityContent = '活动商品，满' + this.data[i].activityRuleList[j].conditionAmount + '元，已减：' + currentActivityReduceAmount + '元'
            //                         this.activityReduceAmount += currentActivityReduceAmount
            //
            //                         this.data[i].activityRuleList[j].checked = index
            //                         break
            //                     }
            //                 } else {
            //                     if(activityTotalNum >= this.data[i].activityRuleList[j].conditionNum) {
            //                         // 选中了促销单选按钮
            //                         var index = j;
            //                         // if(this.data[i].activityRuleList[j].checked > -1) {
            //                         // index = this.data[i].activityRuleList[j].checked;
            //                         // }
            //                         var currentActivityReduceAmount = activityTotalAmount - activityTotalAmount * this.data[i].activityRuleList[index].benefitDiscount/10;
            //                         currentActivityReduceAmount = Math.round(currentActivityReduceAmount*100)/100
            //                         this.data[i].activityContent = '活动商品，打' + this.data[i].activityRuleList[j].benefitDiscount + '折，已减：' + currentActivityReduceAmount + '元'
            //                         this.activityReduceAmount += currentActivityReduceAmount
            //
            //                         this.data[i].activityRuleList[j].checked = index
            //                         break
            //                     }
            //                 }
            //             }
            //         } else {
            //             for(j=0; j<this.data[i].cartInfoList.length; j++) {
            //                 if (this.data[i].cartInfoList[j].isChecked == 1) {
            //                     // 计算促销金额
            //                     this.total += this.data[i].cartInfoList[j].skuPrice * this.data[i].cartInfoList[j].skuNum;
            //                     this.count += 1
            //                 }
            //             }
            //         }
            //     }
            // },
            compute() {
                if(this.data == null) return
                // debugger
                this.count = 0
                for(var i=0; i<this.data.length; i++) {
                    this.total += this.data[i].skuPrice * this.data[i].skuNum
                    if (this.data[i].isChecked == 1) {
                        this.count += 1
                    }
                }
            },

            close() {
                $(".promotion-tips").hide()
            },

            activitySure() {
                this.compute()
                this.close()
            },

            addToCart(skuId, skuNum=1) {
                cart.addToCart(skuId, skuNum).then(response => {
                    this.init()
                })
            },

            add(item) {
                this.addToCart(item.skuId, 1)
            },

            down(item) {
                if(item.skuNum > 1) {
                    this.addToCart(item.skuId, -1)
                }
            },

            checkCart(item) {
                var isChecked = item.isChecked
                if (isChecked == 1) {
                    isChecked = 0
                } else {
                    isChecked = 1
                }
                cart.checkCart(item.skuId, isChecked).then(response => {
                    this.compute()
                })
            },

            deleteCart(skuId) {
                cart.deleteCart(skuId).then(response => {
                    console.log('刪除成功')
                    this.init()
                })
            },

            trade() {
                //  debugger
                if(!auth.isLogin()) {
                    window.location.href = 'http://gmall.gmall.com/login.html?originUrl='+window.location.href
                    return
                }

                var isChecked = 0
                for(var i=0; i<this.data.length; i++) {
                    for(j=0; j<this.data[i].cartInfoList.length; j++) {
                        if (this.data[i].cartInfoList[j].isChecked == 1) {
                            isChecked = 1
                            break
                        }
                    }
                }
                if(isChecked == 1) {
                    window.location.href = 'http://order.gmall.com/trade.html'
                } else {
                    alert('请选择购买的商品')
                }
            },

            getCouponInfo(couponId) {
                activity.getCouponInfo(couponId).then(response => {
                    this.data.forEach(carInfoVo =>{
                        if(carInfoVo.cartInfoList != null) {
                            carInfoVo.cartInfoList.forEach(item => {
                                if(item.couponInfoList != null) {
                                    item.couponInfoList.forEach(couponInfo => {
                                        if(couponId == couponInfo.id) {
                                            // 已领取
                                            couponInfo.isGet = 1
                                            // 未使用
                                            couponInfo.couponStatus = 'NOT_USED'
                                        }
                                    })
                                }
                            })
                        }
                    })
                })
            },

            activityShow(skuId) {
                var top = document.getElementById('activity_a_'+skuId).offsetTop+document.body.scrollTop;
                $("#activity_"+skuId).css("top", top+20)
                $("#activity_"+skuId).show()
            },

            couponInfoShow(skuId) {
                var top = document.getElementById('couponInfo_a_'+skuId).offsetTop+document.body.scrollTop;
                $("#couponInfo_"+skuId).css("top", top+20)
                $("#couponInfo_"+skuId).show()
            }
        }
    })
</script>
</body>
</html>
